//
//  L_SongClassifyCollectionViewCell.m
//  音悦咖
//
//  Created by dllo on 15/7/16.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "L_SongClassifyCollectionViewCell.h"

@implementation L_SongClassifyCollectionViewCell


- (void)dealloc
{
    [_backGroundImage release];
    [_mainImage release];
    [_mainLabel release];
    [_subLabel release];
    [_songClassModel release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        // 创建底色image
        self.backGroundImage = [[UIImageView alloc] init];
        self.backGroundImage.backgroundColor = [UIColor clearColor];
        [self addSubview:self.backGroundImage];
        [_backGroundImage release];
        
        // 创建image
        self.mainImage = [[UIImageView alloc] init];
        self.mainImage.backgroundColor = [UIColor clearColor];
        [_backGroundImage addSubview:self.mainImage];
        [_mainImage release];
        
        // 创建mainLabel
        self.mainLabel = [[UILabel alloc] init];
        self.mainLabel.textColor = [UIColor whiteColor];
        [self.mainLabel.layer setCornerRadius:8];
        [_backGroundImage addSubview:self.mainLabel];
        [_mainLabel release];
        
        // 创建subLabel
        self.subLabel = [[UILabel alloc] init];
        self.subLabel.textColor = [UIColor whiteColor];
        self.subLabel.font = [UIFont systemFontOfSize:15];
        [_backGroundImage addSubview:self.subLabel];
        [_subLabel release];

        
        
    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.backGroundImage.frame = self.bounds;
    self.mainImage.frame = CGRectMake(5, 5, self.frame.size.width - 10, self.frame.size.height / 4 * 3 );
    [self.mainImage.layer setCornerRadius:8];
    [self.mainImage setClipsToBounds:YES];
    self.mainLabel.frame = CGRectMake(5, self.mainImage.frame.size.height + 5, self.mainImage.frame.size.width, (self.frame.size.height - self.mainImage.frame.size.height - 10) / 2);
    self.subLabel.frame = CGRectMake(5, self.mainLabel.frame.origin.y + self.mainLabel.frame.size.height, self.mainImage.frame.size.width, self.mainLabel.frame.size.height);
    
    
}

#pragma mark - 赋值
- (void)setSongClassModel:(L_SongClassifyModel *)songClassModel
{
    if (_songClassModel != songClassModel) {
        [_songClassModel release];
        _songClassModel = [songClassModel retain];
    
    }
    
    // 赋值
    [self.mainImage setImageWithURL:[NSURL URLWithString:songClassModel.pic] placeholderImage:[UIImage imageNamed:@"backgound.png"]];
    NSArray *arr = [songClassModel.title componentsSeparatedByString:@"- "];
    
    self.mainLabel.text = arr[1];
    self.subLabel.text = arr[0];
    
}

@end
